//
//  HPBoutique.m
//  wedding
//
//  Created by 常宽 on 15/1/16.
//  Copyright (c) 2015年 常宽. All rights reserved.
//

/***********精品视频和精品婚礼图文混编自定义view***************/

#import "HPBoutique.h"
#import "BoutiqueModel.h"

#define WIDTH self.frame.size.width
#define HEIGHT self.frame.size.height

@interface HPBoutique ()

/// 图片
@property (nonatomic, retain)UIImageView *HPBImageView;
/// 标题
@property (nonatomic, retain)UILabel *HPBTitle;
/// 内容数
@property (nonatomic, retain)UILabel *HPBCount;
@end

@implementation HPBoutique

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {//初始化视图并加载
        self.HPBImageView = [[UIImageView alloc]init];
        [self addSubview:_HPBImageView];
        
        self.HPBTitle = [[UILabel alloc]init];
        [self addSubview:_HPBTitle];
        
        self.HPBCount = [[UILabel alloc]init];
        [self addSubview:_HPBCount];
        
        self.model = [[BoutiqueModel alloc]init];
    }
    return self;
}

- (void)layoutSubviews
{//根据self.view的大小确定子视图大小
    [super layoutSubviews];
    self.HPBImageView.frame = CGRectMake(0, 0, WIDTH, HEIGHT / 6 * 3.5+10);
    //防止拉伸
    self.HPBImageView.clipsToBounds = YES;
    self.HPBImageView.contentMode = UIViewContentModeScaleAspectFill;
    //磨成圆角
    self.HPBImageView.layer.cornerRadius = 3;
    //色块,布局用
    self.HPBImageView.backgroundColor = [WebColor lightPink];
    //打开用户交互
    self.HPBImageView.userInteractionEnabled = YES;
    
    
    self.HPBTitle.frame = CGRectMake(0, HEIGHT / 6 * 3.5 + 10, WIDTH, HEIGHT / 6 - 5);
//    self.HPBTitle.backgroundColor = [WebColor lightPink];
    self.HPBTitle.userInteractionEnabled = YES;
    
    self.HPBTitle.textColor = [WebColor lavenderBlush];
    self.HPBTitle.font = [UIFont boldSystemFontOfSize:8];
    self.HPBTitle.textAlignment = NSTextAlignmentCenter;

    
    self.HPBCount.frame = CGRectMake(0, (HEIGHT / 6 * 3.5 + 5) + (HEIGHT / 6), WIDTH, HEIGHT / 6 - 5);
//    self.HPBCount.backgroundColor = [WebColor lightPink];
    self.HPBCount.userInteractionEnabled = YES;
    
    self.HPBCount.font = [UIFont boldSystemFontOfSize:8];
    self.HPBCount.textColor = [WebColor lavenderBlush];
    self.HPBCount.textAlignment = NSTextAlignmentCenter;
    
    /// 加载数据
    NSURL *url = [NSURL URLWithString:self.model.cate_logo];
    [self.HPBImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"NoPicture.jpg"]];
    self.HPBTitle.text = self.model.cate_name;
    self.HPBCount.text = [NSString stringWithFormat:@"(%@)", self.model.count];
}
/// 添加点击方法
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    // 当手指离开view的时候,执行代码
#pragma clang diagnostic push   // 宏在ARC模式下添加
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    // 让绑定的对象(target)去执行 相应的方法(action)
    [self.target performSelector:self.action withObject:self];
#pragma clang diagnostic pop
}


@end
